Reducing Memory Usage

This is my first post here and I'm trying to learn DXL to make my job a little easier. I've been having problems keeping my memory usage low. The code below is called in batch mode via the command line. When the code runs, its memory usage quickly increases to about 400MB until the following message pops up:

-I- DXL: execution halted

Can you guys please help me out?

Module m = read("path of module", false, true)
Stream output = write("path\\reqs.txt")
Link l
Object o, req
Buffer srcName = create
int dummy, dummy2
ModName_ srcModRef

Baseline b = getMostRecentBaseline( m )
output << major(b) "." minor(b) "\n"
for o in m do
{
    isReq = o."Req?"
        if( isReq )
        {     
                output << o."ReqID" ":"
                
                //pre load all incoming 7L link modules
                for srcModRef in o <- "*" do
                {
                        srcName = name( srcModRef )
                        if( srcName[0:1] == "7L" && !open(srcModRef) )
                        {
                                read( fullName(srcModRef), false, true )
                        }
                }
                
                //Read tests linked to object
                for l in o <- "*" do
                {
                        req = source l
                        output << req."ReqID" " "
                }
                output << "\n"
        }
}

close( output )

 


SalD - Tue Feb 18 00:41:49 EST 2014

Re: Reducing Memory Usage
Mathias Mamsch - Tue Feb 18 06:57:56 EST 2014

400MB are not much for a DOORS process and they are no obvious memory problems with your code, despite the fact, that you are never closing modules which can make your process run out of memory on large module sets simply due to the size in memory of the modules.

Anyway this reminds me, that I had a very similar stupidity with a DOORS batch process, where I searched for a couple of hours for the reason by DXL ended with the same error message as yours... The solution was so easy:

Add a "pragma runLim, 0" at the start of your DXL to avoid DXL timeout.

Maybe this will help you. If not, there might be a more serious problem. Regards, Mathias

Re: Reducing Memory Usage
SalD - Tue Feb 18 14:55:25 EST 2014

Mathias Mamsch - Tue Feb 18 06:57:56 EST 2014

400MB are not much for a DOORS process and they are no obvious memory problems with your code, despite the fact, that you are never closing modules which can make your process run out of memory on large module sets simply due to the size in memory of the modules.

Anyway this reminds me, that I had a very similar stupidity with a DOORS batch process, where I searched for a couple of hours for the reason by DXL ended with the same error message as yours... The solution was so easy:

Add a "pragma runLim, 0" at the start of your DXL to avoid DXL timeout.

Maybe this will help you. If not, there might be a more serious problem. Regards, Mathias

I did try that and got the same results. After a certain point, which is consistent for every run, the halt message appears.

 

Edit: When running the script on an open instance of doors, I received a timeout error, even when using pragma runLim, 0

Edit2: Thank you a lot for the help. It always is the simple things. I didn't realize that runlim and runLim are different.

Re: Reducing Memory Usage
llandale - Thu Feb 20 15:31:49 EST 2014

SalD - Tue Feb 18 14:55:25 EST 2014

I did try that and got the same results. After a certain point, which is consistent for every run, the halt message appears.

 

Edit: When running the script on an open instance of doors, I received a timeout error, even when using pragma runLim, 0

Edit2: Thank you a lot for the help. It always is the simple things. I didn't realize that runlim and runLim are different.

Have a nagging memory of recieving halt messages when I got into an infinate recursive function.  Calling the function adds to the stack and the stack runs out of space.  You CAN increase it, but I'm guessing you have a coding problem instead.

My notes say the default "stack" in v8 of DOORS was 4096; for v9 it is 16384.  Someone please verify since I don't recall.  You change the stack size:

pragma stack, 16384

The "integer" must be spelled out, you cannot say "4096*16*16" since the pragma is resolved at interpret time which doesn't do any arithmetic calculations.  I have my one huge program set to "147456", otherwise I haven't had a problem.

-Louie

I find the following "theory" rather sound practice:
[1] Recursive functions should check for the extreme conditions (in DXL, typically a "null" input value) and exit quickly and gracefully.  Otherwise allow the Recursion to proceed. 
[2]  I have also found it far easier if the recursive function calls itself, rather than allowing some chain of functions to "recurse" back to the original; which is practically impossible for someone else to follow.  The recurse function of course can call some other function to calculate whatever on the current input to the Recurse function.  If I am unable to write the Recurse function so it calls itself, then I find I have not conceptualized the recursive algorithm adequately and am just begging for problems.  Put another way, if I need a "forward reference" than I've made a mistake.